package cn.mcch.investigator.viewdelegate.impl;


import java.util.List;

import cn.mcch.investigator.R;
import cn.mcch.investigator.adapter.base.CommonAdapter;
import cn.mcch.investigator.adapter.base.ViewHolder;
import cn.mcch.investigator.application.InvestigatorApplication;
import cn.mcch.investigator.model.bean.OrderExport;
import cn.mcch.investigator.model.impl.OrderExportModelImpl;
import cn.mcch.investigator.observer.InvestigatorObserverable;
import cn.mcch.investigator.presenter.BasePresenter;
import cn.mcch.investigator.presenter.IExportOrderPresenter;
import cn.mcch.investigator.utils.JsonUtils;

/**
 * Created by Administrator on 2016/12/25.
 */
public class OrderExportPresenterImpl extends BasePresenter<OrderExportViewDelegateImpl, OrderExportModelImpl> implements IExportOrderPresenter {

    private List<OrderExport> orderExportList;
    private CommonAdapter<OrderExport> adapter;

    @Override
    public Class<OrderExportViewDelegateImpl> getViewDelegateClass() {
        return OrderExportViewDelegateImpl.class;
    }

    @Override
    public Class<OrderExportModelImpl> getModelClass() {
        return OrderExportModelImpl.class;
    }

    @Override
    public void viewBindData(OrderExportViewDelegateImpl viewDelegate, String json) {
        orderExportList = JsonUtils.fromJsonToList(json, OrderExport.class);
        adapter = new CommonAdapter<OrderExport>(InvestigatorApplication.getInstance(), R.layout.list_item_order_export, orderExportList) {
            @Override
            protected void convert(ViewHolder viewHolder, OrderExport item, int position) {
                viewHolder.setText(R.id.tv_order_no, String.format("报案号:%s", item.sn))
                        .setText(R.id.tv_customer_car, String.format("车牌号:%s", item.no))
                        .setText(R.id.tv_order_attr, String.format("案件属性:%s", item.attrValue))
                        .setText(R.id.tv_order_type, String.format("案件类型:%s", item.type))
                        .setText(R.id.tv_customer_car_type, String.format("车型:%s", item.car))
                        .setText(R.id.tv_customer, String.format("客户姓名:%s", item.name))
                        .setText(R.id.tv_customer_phone, String.format("客户手机:%s", item.tel))
                        .setText(R.id.tv_order_area, String.format("出险地址:%s", item.areaValue + " " + item.addr));
                // 录入时间
                viewHolder.setText(R.id.tv_lrsj, String.format("录入时间:%s", item.addtime));
            }
        };
        mViewDelegate.setAdapterViewAdapter(R.id.lv_order_export, adapter);
    }

    public void setIetmClickPosition(int position) {

        InvestigatorObserverable.notifyObservers(500, orderExportList.get(position));
    }
}
